import kline 
import pandas as pd
import numpy as np
import talib
import akshare as ak
import pprint
import tkinter as tk
def test():
    line ={'name':'mwg','age':25}
    res=[]

    res.append(line)
    line ={'name':'xdd','age':23}
    res.append(line)

    print(res)
    
def test2():
    for i in range(10-2):
        print(i)
        

def test3():
    line=kline.Kline()
    print(line.line_start)
    

def test4():
    data = pd.read_excel("d:/test/t2.xlsx")    
    print(data)
    
    
#计算macd
def cal_macd():
    data = pd.read_excel("d:/test/t2.xlsx")
    close = data['close']
    data2 = {'close': [100, 102, 105, 103, 106, 108, 110, 109, 112, 115,100, 102, 105, 103, 106, 108, 110, 109, 112, 115,100, 102, 105, 103, 106, 108, 110, 109, 112, 115,100, 102, 105, 103, 106, 108, 110, 109, 112, 115]}
    close2 = pd.DataFrame(data2)['close']
    macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
    print(macd)
    macd, signal, hist = talib.MACD(close2, fastperiod=12, slowperiod=26, signalperiod=9)
    print(macd)
    
def macd2():
    data = ak.stock_zh_a_minute('sh600000','5')#A股分时历史行情
    data2 = data.iloc[10:200]
    print(data2['close'])
    macd, signal, hist = talib.MACD(data2['close'], fastperiod=12, slowperiod=26, signalperiod=9)
    # pd.set_option('display.max_columns', 1000)
    pd.set_option('display.max_rows', 10000)
    #打印macd数据
    print(macd,signal,hist)
    #绘制macd图
    import matplotlib.pyplot as plt
    plt.plot(macd, label='macd')
    plt.plot(signal, label='signal')
    plt.plot(hist, label='hist')
    plt.legend()
    plt.show()
    
    
def macd3():
    cprice = np.random.rand(100)*100
    macd, signal, hist = talib.MACD(cprice, fastperiod=12, slowperiod=26, signalperiod=9)
    # pd.set_option('display.max_columns', 1000)
    print(macd)

def test5():
    for i in range(5,10):
        print(i)

def testfor():
    data = [1,2,3,4,5,6,7,8,9,10]
    #从第3个开始循环
    for i in range(1,len(data)-1):
        print(data[i])

def testtk():
    root = tk.Tk()
    root.geometry('800x600')
    
    
    root.mainloop()

# test4()
# cal_macd()

# macd2()
# macd3()
# test5()
# testfor()
